package com.medical.doctor.service.impl;

import com.medical.doctor.controller.vo.AuditVo;
import com.medical.doctor.controller.vo.LivesVo;
import com.medical.doctor.dao.DoctorMessageDao;
import com.medical.doctor.service.DoctorMessageService;
import io.swagger.models.auth.In;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Date;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.medical.common.utils.PageUtils;
import com.medical.common.utils.Query;

import com.medical.doctor.dao.DoctorLiveDao;
import com.medical.doctor.entity.DoctorLiveEntity;
import com.medical.doctor.service.DoctorLiveService;


@Service("doctorLiveService")
public class DoctorLiveServiceImpl extends ServiceImpl<DoctorLiveDao, DoctorLiveEntity> implements DoctorLiveService {
    @Autowired
    private DoctorMessageDao doctorMessageDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<DoctorLiveEntity> wrapper = new QueryWrapper<>();
        wrapper.orderByAsc("hot_degree").orderByAsc("status");
        IPage<DoctorLiveEntity> page = this.page(
                new Query<DoctorLiveEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

    @Override
    public void createLive(Integer doctorId,DoctorLiveEntity doctorLiveEntity) {
        //得到医生的详细信息
        AuditVo doctor = doctorMessageDao.findByDoctorId(doctorId);
        BeanUtils.copyProperties(doctor,doctorLiveEntity);
        doctorLiveEntity.setCreateTime(new Date());
        doctorLiveEntity.setStatus("1");
        baseMapper.insert(doctorLiveEntity);
    }

    @Override
    public List<LivesVo> lives(Integer doctorId) {
        AuditVo doctor = doctorMessageDao.findByDoctorId(doctorId);
        return doctorMessageDao.livesCount(doctor.getDoctorName());
    }

    @Override
    public Boolean liveagain(Integer id) {
        //得到医生的详细信息
        DoctorLiveEntity doctorLiveEntity = baseMapper.selectById(id);
        doctorLiveEntity.setStatus("1");
        doctorLiveEntity.setCreateTime(new Date());
        baseMapper.insert(doctorLiveEntity);
        return true;
    }

}